//
// Unihan Input Method
//
// Copyright © 2002-2007 Sun Wah Linux Ltd.
//
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
// USA
//
// $Id: SWTable.h 757 2007-05-10 08:19:31Z roger $
//

#ifndef _SW_TABLE_H
#define _SW_TABLE_H

#include <string.h>
#ifndef Bool
# define Bool int
#endif

#ifndef TREU
# define TRUE 1
#endif

#ifndef FALSE
# define FALSE 0
#endif

#define FILE_SUFFIX_BS ".bs"
#define FILE_SUFFIX_CMN ".cmn"
#define FILE_SUFFIX_USR ".usr"

#define FILE_SUFFIX_TAB ".tab"
#define FILE_SUFFIX_BIN ".bin"
#define FILE_SUFFIX_UPB ".upb"
#define FILE_SUFFIX_ADJ ".adj"

#define FILE_TYPE_BASE "base"
#define FILE_TYPE_COMMON "common"
#define FILE_TYPE_USER "user"

#define ENCODING_UTF_8 "UTF-8"
#define ENCODING_BIG5HKSCS "BIG5HKSCS"
#define ENCODING_BIG5 "BIG5"
#define ENCODING_GB2312 "GB2312"
#define ENCODING_GB18030 "BG18030"

#define IM_TBL_SIG "SWinGenTab1"

#define ENAME_MAX_LEN 20
#define CNAME_MAX_LEN 30
#define KEYNAME_MAX_LEN 7
#define FREQ_CELL 3

#define idx(x) (((unsigned char)x) - 0x20)
#define UTF_CN_TO_INT_IDX(index, cn) ((char*)&index)[3]=0x00; \
			((char*)&index)[2]=cn[0]; \
			((char*)&index)[1]=cn[1]; \
			((char*)&index)[0]=cn[2]

typedef unsigned int CN_IDX;

typedef enum _Hints {
	SHOW_AS_U_GO = 1,
	UNDEFINED = 1 << 1
} Hints;

typedef struct _TableHeader {
	char ename[ENAME_MAX_LEN];
	char cname[CNAME_MAX_LEN];
	Hints hints;
	int numKey;
	int numChar;
	int keyTableLen;
	int charTableLen;
	CN_IDX minChar;
	int numRevChar;
} TableHeader;

typedef struct _BinHeader {
	char ename[ENAME_MAX_LEN];
	int numKey;
	int numCharList;
	int keyTableLen;
	int charTableLen;
} BinHeader;

typedef struct _KeyNameTable {
	char name[KEYNAME_MAX_LEN];
} KeyNameTable;

typedef struct _FastIdx {
	int offset;
} FastIdx;

typedef struct _CheckListIndex {
	int keyOff;
	int charOff;
	int frqOff;
	int maxFrqOff;
	int stickOff;
} CheckListIndex;

typedef struct _SimCheckListIndex {
	int keyOff;
	int charOff;
} SimCheckListIndex;

/* RevSearchTable is used to search CheckListIndex , reverse search table */
typedef int RevSearchTable;

typedef int Frequence;
typedef int MaxFrequence;

#define STICK_SIZE 3

typedef struct _CharStickTable {
	int prefixOff[STICK_SIZE];
	int suffixOff[STICK_SIZE];
} CharStickTable;

typedef struct _BaseTable {
	void *map;
	size_t size;
	char *tableSig;
	TableHeader *header;
	KeyNameTable *keyName;
	FastIdx *fastIdx;
	CheckListIndex *checkListIndex;
	char *keyData;
	char *charData;
	RevSearchTable *rsTable;
} BaseTable;

typedef struct _Adjuster {
	void *map;
	size_t size;
	int numMaxFreq;
	MaxFrequence *maxFreqTable;
	Frequence *freqTable;
	CharStickTable *stickTable;
} Adjuster;

typedef struct _PhraseTableList {
	void *map;
	size_t size;
	char *tableSig;
	BinHeader *header;
	FastIdx *fastIdx;
	SimCheckListIndex *simCheckListIndex;
	char *keyData;
	char *charData;
	struct _PhraseTableList *next;
} PhraseTableList;

#endif /* _SW_TABLE_H */

// vi:ts=4:nowrap:cin:expandtab
